package com.my.study.designPatterns.compoundPattern;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Observerable implements QuackObserverable{

    private List<DuckObserver> duckObservers = new ArrayList<>();

    private QuackObserverable duck;


    public Observerable(QuackObserverable duck) {

        this.duck = duck;
    }

    @Override
    public void registerObserver(DuckObserver observer) {

        duckObservers.add(observer);
    }

    @Override
    public void notifyObservers() {

        Iterator<DuckObserver> iterator = duckObservers.iterator();
        while (iterator.hasNext()){
            iterator.next().update(duck);
            System.out.println("notify------------");
        }
    }
}
